Repository navigation
Output parameters on stored definitions, and captures on their calls - #300
Merged
Merged
Conversation
A DbNonQuery definition now declares what it reads back: Output<TOut>() for a model, Output<T>(name) and Output<T>(name, precision, scale) for one value, and OutputDecimal for a nullable decimal; the same on the typed-parameters form. The result is an OutputDbNonQuery that is bound with Using and run with ExecuteOutputAsync. The outputs are checked when the definition is declared, and every message names the definition and the model and gives the fix. A bound write also gets ExecuteReturnAsync<T>, checked at the call. A definition's call matches and adds its outputs through the code the commands use (now OutputBinding), so the rules are the same. Named outputs of a definition match the way AddParam names match (exact, ignoring case, ignoring case and underscores, after a common prefix). The runner that fills captures from a definition's call is added here and used by the next change. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A capture can now be added per call on a query made from a stored DbQuery definition (X.Using(factory).AddParam(...).CaptureOutput(...)), and on a bound write or scalar call through extension methods of those two kinds. A call made from Output has no capture members, so a capture there is a compile error. A capture before or after AddParam gives the same call, and a kept or branched call that carries a capture runs once. A definition's call fills its captures through its own runner (DbQueryRunner.RunCapturedAsync and the write and scalar forms), which claims the captures when the terminal is called, copies the outputs off the command before it is disposed, and completes every capture on every exit. A query from a definition has no command, so its cancellation token and its captures are its own. ExecuteReturnAsync refuses a capture that reads the return code and runs beside an output-only capture. A bound call's equality includes its captures by reference; a call without one hashes as before. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
CaptureOutput now names its output parameter after the variable it fills: CaptureOutput(out DbCapture<int> total) reads @ToTal, and the name can be passed last instead: CaptureOutput(out DbCapture<int> x, "total"). The compiler supplies the variable's text; a new scanner reads the last identifier from it (a declaration, a local, this.total, state.total, arr[0].Total) or from a typed string, with one rule for both ($ and # allowed, one leading @ or : dropped, a discard, an element access or a missing name refused with the fix). The name is matched the way AddParam's names are, over the name as written and without a field prefix. Texts that are not one plain name are worked out once each. The name-first forms are gone on the command, MappedQuery (and its skip and take views) and the bound calls. The generic shape overload is replaced by CaptureOutput(out DbCapture<decimal>, precision, scale), so a wrong type with a shape is a compile error; CaptureOutputDecimal keeps the nullable form. A model ignores the name and never refuses one; when its member matches nothing, the message says the name was not used and gives both fixes. Two captures that resolve to one parameter fail the run with a capture fix. Every message that named a capture form names the new ones, and the source in a message is the command text or the procedure, as the command's messages say it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The output-parameter sample passes the name last, as the capture members now take it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A capture's name goes through the tiers over the candidates it carries, the name as written and, for a field prefix, the name without it, and never through the memo of the named outputs, which is keyed by the name and answers for one candidate. ExecuteOutputAsync's named forms and a definition's Output(name) keep that memo. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The unobserved-fault test listened to every unobserved task exception of the test run, so an unrelated test's exception failed it once. Its fault now names a unique procedure and only exceptions that carry that name are counted. It still fails if its own fault goes unobserved. The comments on captures now say that a query keeps only its own captures and a run combines them with the command's current ones, the command's first; a query from a definition has no command. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The output samples now lead with the definition form: a static readonly definition, then per call Using, the parameters and the capture. The ad hoc command form follows each one. New samples cover typed values with outputs, the return code of a definition, a model capture, a write and a scalar with captures, a pooled stream, and the ways a capture takes its name. The samples run against procedures created in tempdb when LocalDB is available, and Program.cs checks what they return. The expressive commands article, the release notes and the what's new page describe definitions that declare and read outputs, and captures on the calls of a stored definition. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A query made from a stored definition now has tests that its capture is filled when a Channel reader, a bounded Channel reader, a source block or a target block finishes its pass. A capture added before or after a parameter on a bound write gives the same call, and a named output called ReturnValue reads the declared parameter, not the return code. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Correct two comments: the terminal throws when its own conversion fails while the captures keep the values already delivered, and the capture name cache holds one weak entry per distinct non-plain text. An empty typed capture name now gets a message for typed text, not the one about the compiler. A leading underscore is no longer a capture name candidate of its own; only m_ and s_ are stripped, and the matcher's underscore tier handles the rest. The doc line says the same. Add tests: a model capture beside ExecuteReturnAsync reads each value once (fake connection and SQL Server definition); a decimal shape with a non-decimal capture does not compile and infers DbCapture<decimal> on a command and on a mapped query. Drop duplicate name rows, a repeated comment and a trailing blank line. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sample chains follow the layout rule: the first call on the receiver's line, one call per line, and each long definition broken after the equals sign. The sample Blog factory is static readonly again, and the harness supplies its connection string through an environment variable set before the class is first used. The raw command sample now returns the return code it reads, and the harness checks it. The ad hoc capture prose matches the samples, a field capture notes that it holds one call's capture, the field comment no longer implies an underscore prefix is stripped, and the name rule lists m_ and s_ as the field prefixes. Long harness lines are wrapped. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…acters A name of only white space has characters, so the message now says it is empty or only white space. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The language-version binding tests declared captures they never used, which the analyzers report. Each capture now goes through a helper that compiles only when the value has the expected type. The existing-local case keeps its declaration on purpose. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The captured write and scalar runs took a bool that chose whether the return code is read. They now take the function that gives the layout the run reads: the captures' layout as is, or with the return code after it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Master moved the outputs' resolution unchanged; the definitions' shared resolution (OutputBinding) now carries the metadata check, and the name-first capture docs master extended are removed here. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A stored definition's call that reads output parameters now reads the procedure's parameter metadata, once, as a command's call does, so an output on an input parameter or a decimal with a lower scale is refused before the run on both paths. The metadata tests use the name-last capture forms and cover a definition and a capture on its call. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An output named after an input parameter of a procedure is now refused before the run, from the procedure's metadata, instead of by SQL Server. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Two definitions of one procedure that read different outputs compared equal, and so did their bound calls. The outputs are now compared by value (a named output builds its layout per declaration), and a definition without outputs hashes as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ExecuteOutputAsync built the text of the refusal beside a capture on every call. It now passes a constant format and the model, and the text is formatted only when a capture is there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stored definitions can declare and read output parameters, captures work on the calls of a stored definition, and a capture takes its parameter's name from its variable.
Builds on #297.
Outputs on a definition
A
DbNonQuerydefinition declares what it reads back, once, where it is stored:Output<TOut>()reads a model.Output<T>(name)andOutput<T>(name, precision, scale)read one value, andOutputDecimal(name, precision, scale)reads a nullable decimal. All four also work on the typed-parameters form,DbNonQuery.Procedure(...).Params<TParams>().ExecuteReturnAsync<T>()for the return code. It is refused at the call on a text definition, because a text definition has no return code.AddParamnames do: exact, ignoring case, ignoring case and underscores, then without a common prefix.Captures on a definition's calls
A capture is per call, after
Usingand the parameters, and never on the stored definition:DbQuerydefinition (every terminal, stream, buffer, Channel and Dataflow form), and on bound write and scalar calls. A call made fromOutputhas no capture members, so a capture there is a compile error.AddParamgives the same call.CaptureReturnon a text definition is refused at the call.ExecuteReturnAsyncrefuses a capture that also reads the return code, and runs beside a capture that reads only outputs.nullwithout a capture. It is copied on eachAddParam, and each terminal tests it once. Equality includes it by reference, and a call without one hashes as before.The capture name comes from the variable
CaptureOutput(out DbCapture<int> total)reads@total. The name can also be passed last:CaptureOutput(out DbCapture<int> x, "total").this.total,state.total,arr[0].Total. A typed name follows the same rule:$and#are allowed, and one leading@or:is dropped.AddParamnames are, over the name as written and without anm_ors_field prefix. A text that is not one plain name is worked out once and cached weakly.CaptureOutput(out DbCapture<decimal> x, precision, scale, name)replaces the generic shape overload, so a wrong type with a shape does not compile.CaptureOutputDecimalkeeps the nullable form.Docs and samples
static readonlyfield, then the per-call chain. The ad hoc command form follows.Tests
CancelOnEarlyStop(); single use; before or afterAddParam.Outputcall does not compile, that a wrong type with a decimal shape does not compile, and thatout varwith a shape infersDbCapture<decimal>.Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com
Co-Authored-By: Claude Sonnet 5.5 noreply@anthropic.com
🤖 Generated with Claude Code